<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    

    <script>
        // 模拟一个dispatch函数
        // A   redux
        // B   redux-thunk

        function dispatch(action) {
            if (typeof action === "object") {
                if (action.type) {
                    console.log('dispatch正常调用了')
                } else {
                    throw Error("对象中必须有一个type属性")
                }
            } else {
                throw Error("dispatch的第一个参数必须是一个对象")
            }
        }

        // 保留原来的dispatch
        let oldDispatch = dispatch

        // 对原来的dispatch进行赋值
        dispatch = (action) => {
            if (typeof action === "function") {
                console.log('我现在可以传递函数了')
            } else {
                oldDispatch(action)
            }
        }

        // dispatch(() => {
        //     axios.get('/getList').then(res => {
        //         dispatch({ type: "INIT", list: res.data })
        //     })
        // })

        dispatch({})
    </script>
</body>
</html>